using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.Global;


public partial class Provider_ProviderHome : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null || Session[CE.Global.General.ProviderCompanyId] == null)
        {
            Response.Redirect("~/Provider/ProviderSecureLogin.aspx");
        }
        else 
        {   //20-Jan-2011  [CarInsurance] Only
            //Response.Redirect("~/Provider/CarInsurance/TableMatching.aspx");
        }

        LoadPageLink();
        CheckProviderUserType();

        if (!Page.IsPostBack)
        {
            CE.Global.General.ClearAllSession(this.Page, "all");
            CE.User.AccountStatusDB _accountStatusDB = new CE.User.AccountStatusDB();
            int _pwdStatus = _accountStatusDB.GetLastPasswordChagedStatus(Convert.ToInt64(Session[CE.Global.General.UserId].ToString()));
            if(_pwdStatus == 1)
            {
                //Response.Redirect("UserMessage.aspx?ErrorCode=1994");
                Response.Redirect("UserMessage.aspx?mt=UM&ec=1994");
            }
            else if (_pwdStatus == 0)
            {
                Response.Redirect("ChangePassword.aspx");
            }
            //if (Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()) == 23)
            //{
            //    hlPAInsurance.Visible = true;
            //}
            //else
            //{
            //    hlPAInsurance.Visible = false;
            //}

            //if (Session[CE.Global.General.UserId].ToString() == "54")  //local 36, live 54 hsbc dummy accnt
            //{
            //    hlPAInsurance.Visible = true;
            //    hlnkTravel.Visible = true;
            //}
            //else
            //{
            //    hlPAInsurance.Visible = false;
            //    hlnkTravel.Visible = false;
            //}

            //if ((Session[CE.Global.General.UserId].ToString() == "53") || (Session[CE.Global.General.UserId].ToString() == "55"))  
            //if (Session[CE.Global.General.UserId].ToString() == "53")
            //{
            //    //local 35, live53 chartis accnt
            //    //local 37, live55 liberty travel accnt
            //    hlnkTravel.Visible = true;
            //    hlnkCar.Visible = false;
            //}

            //if (Session[CE.Global.General.UserId].ToString() == "53") //chartis
            //{
            //    hlViewStatement.Visible = false;
            //    hlProposalForms.Visible = false;
            //}

            //if (Session[CE.Global.General.UserId].ToString() == "174") //RSA
            //{
            //    hlPAInsurance.Visible = false;
            //    hlnkCar.Visible = true;
            //    hlReviewLogs.Visible = false;
            //    hlStatistics.Visible = true;
            //}


        }

    }

    private void LoadPageLink()
    {
        hlnkCar.Visible = false;
        hlnkTravel.Visible = false;
        hlPAInsurance.Visible = false;
        hlReviewLogs.Visible = false;
        hlViewStatement.Visible = false;
        hlStatistics.Visible = false;
        hlProposalForms.Visible = false;

        DataTable _dtMainPage = new DataTable();
        _dtMainPage = General.GetProviderMainPage(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()));

        if (_dtMainPage != null && _dtMainPage.Rows.Count > 0)
        {
            string[] _PageLink = new string[_dtMainPage.Rows.Count];
            for (int i = 0; i < _dtMainPage.Rows.Count; i++)
            {
                _PageLink[i] = _dtMainPage.Rows[i]["CXPageName"].ToString();
            }
            for (int j = 0; j < _PageLink.Length; j++)
            {
                if (_PageLink[j].ToString() == "CXCI")
                {
                    hlnkCar.Visible = true;
                }
                else if (_PageLink[j].ToString() == "CXTI")
                {
                    hlnkTravel.Visible = true;
                }
                else if (_PageLink[j].ToString() == "CXPA")
                {
                    hlPAInsurance.Visible = true;
                }
                else if (_PageLink[j].ToString() == "CXRL")
                {
                    hlReviewLogs.Visible = true;
                }
                else if (_PageLink[j].ToString() == "CXVSTM")
                {
                    hlViewStatement.Visible = true;
                }
                else if (_PageLink[j].ToString() == "CXVSTS")
                {
                    hlStatistics.Visible = true;
                }
                else if (_PageLink[j].ToString() == "CXDPF")
                {
                    hlProposalForms.Visible = true;
                }
            }
        }
        hlnkTravel.Visible = false;
        hlPAInsurance.Visible = false;
        hlReviewLogs.Visible = false;
        hlViewStatement.Visible = false;
        hlStatistics.Visible = false;
    }

    private void CheckProviderUserType()
    {
        Int64 ProviderUserType = General.CheckProviderUserType(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()));
        if (ProviderUserType != 100)
        {
            hlUserAccess.Visible = false;
        }
    }

}
